package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.*;
import net.pinnoocle.playservice.service.impl.ScriptServiceImpl;
import net.pinnoocle.playservice.service.impl.ShopServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-10-21 16:45
 */

@RestController
@RequestMapping("/scriptLabel")
@Api(tags = "剧本标签管理")
public class ScriptLabelController {
    @Autowired
    ScriptServiceImpl scriptService;
    @Autowired
    ShopServiceImpl shopService;

    @GetMapping("labelListWithPage")
    @ApiOperation("剧本标签列表---分页")
    public BaseResult<PageModel<ScriptLabelListPageVo>> labelLabelWithPage(BaseShopSearch shopSearch){
        return new BaseResult<PageModel<ScriptLabelListPageVo>>().ok(scriptService.labelListWithPage(shopSearch));
    }

    @GetMapping("labelList")
    @ApiOperation("剧本标签列表")
    public BaseResult<List<ScriptLabelListVo>> labelList(){
        return new BaseResult<List<ScriptLabelListVo>>().ok(scriptService.labelList());
    }

    @PostMapping("saveLabel")
    @ApiOperation("剧本标签添加")
    public BaseResult<String> saveLabel(@Validated @RequestBody SaveScriptLabelParams params){
        boolean result = scriptService.saveLabel(params);
        if(result){
            return new BaseResult<String>().success("剧本标签添加成功");
        }
        return new BaseResult<String>().error("剧本标签添加失败");
    }

    @PostMapping("updateLabel")
    @ApiOperation("剧本标签编辑")
    public BaseResult<String> updateLabel(@Validated({UpdateGroup.class}) @RequestBody SaveScriptLabelParams params){
        boolean result = scriptService.updateLabel(params);
        if(result){
            return new BaseResult<String>().success("剧本标签编辑成功");
        }
        return new BaseResult<String>().error("剧本标签编辑失败");
    }

    @GetMapping("deleteLabel")
    @ApiOperation("剧本标签删除")
    public BaseResult<String> deleteLabel(@RequestParam("labelId") Integer labelId){
        boolean result = scriptService.deleteLabel(labelId);
        if(result){
            return new BaseResult<String>().success("剧本标签删除成功");
        }
        return new BaseResult<String>().error("剧本标签删除失败");
    }
}
